package edu.imac.angryfood.shapes;

import java.util.ArrayList;

import edu.imac.angryfood.world.Body;

/**
 * A shape built up of other shapes
 * 
 */
public class CompoundShape implements Shape {
	/** Array containing all our forms **/
	private ArrayList<Shape> children = new ArrayList<Shape>();
	/** The body this shape is being used in if any */
	private Body body;

	/**
	 * Constructor
	 */
	public CompoundShape() {
	}
	
	/**
	 * @return the body
	 */
	@Override
	public Body getBody() {
		return body;
	}
	
	/**
	 * Add a child in the array
	 * @param child
	 */
	public void add(Shape child) {
		children.add(child);
	}

	/**
	 * Returns the numbers of the shapes
	 * @return the number of the shapes
	 */
	public int getShapeCount() {
		return children.size();
	}
	
	/**
	 * Returns the shape at the position i in the array
	 * @param i : position of the shape
	 * @return a shape
	 */
	public Shape getShape(int i) {
		return children.get(i);
	}
	
	/**
	 * Create a Body
	 * @body : create this body
	 */
	@Override
	public void createInBody(Body body) {
		for (int i=0;i<children.size();i++) {
			children.get(i).createInBody(body);
		}
	}

	/**
	 * Return the array of shapes
	 */
	@Override
	public ArrayList<org.jbox2d.collision.Shape> getJBoxShapes() {
		ArrayList<org.jbox2d.collision.Shape> shapes = new ArrayList<org.jbox2d.collision.Shape>();

		for (int i=0;i<children.size();i++) {
			shapes.addAll(children.get(i).getJBoxShapes());
		}
		
		return shapes;
	}

	/**
	 * Apply the density to all the children of the shape
	 * @param density : the density of the parent shape
	 */
	@Override
	public void setDensity(float density) {
		for (int i=0;i<children.size();i++) {
			children.get(i).setDensity(density);
		}
	}

	/**
	 * Apply the friction to all the children of the shape
	 * @param friction : the friction of the parent shape
	 */
	@Override
	public void setFriction(float friction) {
		for (int i=0;i<children.size();i++) {
			children.get(i).setFriction(friction);
		}
	}

	/**
	 * Apply the restitution to all the children of the shape
	 * @param rest : the restitution of the parent shape
	 */
	@Override
	public void setRestitution(float rest) {
		for (int i=0;i<children.size();i++) {
			children.get(i).setRestitution(rest);
		}
	}
	
	@Override
	public org.newdawn.slick.geom.Shape getSlickShape() {
		return null;
	}

}
